# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render

# Create your views here.

from django.http import HttpResponse

def index(request):
    return HttpResponse('ok')


# def shop(request,pro_id,city_id):
#     # print(pro_id,city_id)
#     query_params = request.GET
#     # print(query_params)
#     alist = query_params.getlist('a')
#     print(alist)
#     asingle = query_params.get('a')
#     print(asingle)
#     return HttpResponse('我的小餐馆')

def weibo(request):
    # 接收数据
    body = request.body
    print(body)
    # 将bytes类型的数据转换为str类型
    body_str = body.decode()
    print(type(body_str))
    # 将json形式的字符串数据转换为字典
    import json
    data = json.loads(body_str)
    print(data)

    return HttpResponse('weibo json')

def http_res(request):
    return HttpResponse('不要返回对象 因为python的对象只有python认识', status = 200, content_type='text/html')

from django.http import JsonResponse

def res_json(request):
    # data = {
    #     "name":"abc",
    #     "age":"15"
    # }
    # import json
    # # 字段转换为字符串
    # data_str = json.dumps(data)
    # return HttpResponse(data_str,content_type='application/json')

    data = [{
        'name':'abc',
        'age': 11,
    }]
    return JsonResponse(data,safe=False)


def set_cookie(request):
    username = request.GET.get('username')
    response = HttpResponse('set_cookie')
    response.set_cookie(key='username',value=username,max_age=24*3600)
    # response.delete_cookie()
    return response

def get_cookie(request):
    username = request.COOKIES.get('username')
    print(username)
    return HttpResponse('get_cookie')


def register(request,mobile):
    my_mobile = request.GET
    print(my_mobile)
    return HttpResponse('11111111')

